package com.seari.monitor;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.locks.ReentrantLock;

import org.springframework.stereotype.Component;

import com.seari.monitor.impl.RabbitMqMiddlewareMonitor;
import com.seari.monitor.impl.RedisMiddlewareMonitor;
import com.seari.monitor.impl.SimpleRedisMonitor;
import com.seari.utils.LoadPropertiesUtils;

@Component
public class MonitorBootstrap {

	public static ExecutorService service = Executors.newCachedThreadPool();

	//初始化监视器
	public void initMonitorContainer() {
		String[] midWares = LoadPropertiesUtils.getMidWares();  //从配置文件获取要监控的中间件
		if(midWares != null && midWares.length > 0) {
			for (int i = 0; i < midWares.length; i++) {
				String midwName = midWares[i];
				service.submit(new Runnable() {
					@Override
					public void run() {
						dispatchMonitor(midwName);
					}
				});
			}
		}else {
			service.shutdown();
		}
	}

	/**
	 * 选择监控器
	 * @param midWareName
	 */
	public void dispatchMonitor(String midWareName) {
		switch (midWareName) {
			case "redis":
				
				initRedisMonitor();
				break;
			case "rabbitMq":
	
				initRabbitMqMonitor();
				break;
				
			default:
				break;
			}
	}
	
	

	public void initRedisMonitor() {
		new SimpleRedisMonitor().monitorData();
	}
	
	public void initRabbitMqMonitor() {
		new RabbitMqMiddlewareMonitor().monitorData();
	}

	public static void main(String[] args) {
	}
}
